package com.wms_backend.controller;

import com.alibaba.fastjson.JSONObject;
import com.wms_backend.entity.Result;
import com.wms_backend.security.UserDetailsImpl;
import com.wms_backend.service.InboundService;
import com.wms_backend.service.OutboundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/outbound")
public class OutboundController {

    @Autowired
    OutboundService outboundService;

    @PostMapping("/create")
    public Result create(@RequestBody JSONObject param) {
        UserDetailsImpl principal = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String userId = principal.getUserId();
        return outboundService.create(param, userId);
    }

    @PostMapping("/query-inbound")
    public Result queryInbound(@RequestBody JSONObject param) {
        UserDetailsImpl principal = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String userId = principal.getUserId();
        return outboundService.queryInbound(param,userId);
    }

    @PostMapping("/query-outbound")
    public Result queryOutbound(@RequestBody JSONObject param){
        UserDetailsImpl principal = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String userId = principal.getUserId();
        return outboundService.queryByCondition(param,userId);
    }

}
